#!/usr/bin/env bash
# usage: ./**.sh username

# install kernel and drivers
pacman --noconfirm -S linux-xanmod linux-xanmod-headers linux-firmware sof-firmware aic94xx-firmware wd719x-firmware

# set time
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
hwclock --systohc

# locale
sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
sed -i 's/#zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen
locale-gen
echo LANG=zh_CN.UTF-8 >/etc/locale.conf

# hostname
echo $1 >/etc/hostname
echo 127.0.0.1 localhost >/etc/hosts
echo ::1 localhost >>/etc/hosts

# boot
pacman --noconfirm -S grub os-prober efibootmgr
grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=GRUB
echo -e "\nGRUB_DISABLE_OS_PROBER=false" >>/etc/default/grub
# if [ $2 = 1 ]; then
#     sed -i 's/loglevel=3 quiet/loglevel=3 memmap=12M\\$20M quiet/g' /boot/# grub/grub.cfg # xps17 need this to start wifi 现在貌似不用了
# fi
grub-mkconfig -o /boot/grub/grub.cfg

# root password
passwd

# add user to wheel group
sed -i 's/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/g' /etc/sudoers
useradd -m -g wheel $1

# user password
passwd $1
